﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace FieldTools.Util.Helper
{
    //可能会用到的user32函数，按需添加使用，集中管理
    public class User32Helper
    {
        /// <summary>
        /// 按照窗体类名或窗体标题查找窗体，案例中没使用，采用的console专用函数，实际使用根据自己需求来，完整代码中有使用示例
        /// </summary>
        [DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Auto)]
        public static extern IntPtr FindWindow(string lpszClass, string lpszWindow);
        /// <summary>
        /// 显示并设置窗口属性
        /// </summary>
        [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
        public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
        /// <summary>
        /// 设置窗口属性
        /// </summary>
        [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, long dwNewLong);
        /// <summary>
        /// 获取窗口属性
        /// </summary>
        [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
        public static extern long GetWindowLong(IntPtr hWnd, int nIndex);
        /// <summary>
        /// 设置窗口大小
        /// </summary>
        [DllImport("user32.dll", EntryPoint = "MoveWindow", CharSet = CharSet.Auto)]
        public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint);
        /// <summary>
        /// 更改指定子窗口的父窗口
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="hNWnd"></param>
        /// <returns></returns>
        [DllImport("user32.dll", EntryPoint = "SetParent", CharSet = CharSet.Auto)]
        public static extern int SetParent(IntPtr hWnd, IntPtr hNWnd);
    }
}
